//
//  UIButton+Extension.swift
//  01MicroBlog
//
//  Created by Apple on 15/8/3.
//  Copyright © 2015年 heima. All rights reserved.
//

import UIKit

extension UIButton {
    
    convenience init(title:String, textColor:UIColor, textFont:CGFloat, backgroundColor:UIColor) {
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(textColor, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(textFont)
        self.backgroundColor = backgroundColor
    }
    
    convenience init(title:String, backgroundImg:String) {
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        setImage(UIImage(named: backgroundImg), forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(10)
    }
    
    convenience init(imageName: String) {
        self.init()
        
        setImage(imageName)
    }
    
    /// 使用图像名设置按钮图像
    func setImage(imageName: String) {
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        // 提示：如果高亮图片不存在，不会设置
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
    }
}